import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    pathArr: [{ path: '/homepage', name: '我的主页' }],    //home-bar导航数组
    homebarThisIndex: 0,  //home-bar
    homebarOneTime: false //home-bar
  },
  mutations: {
    //点击left-bar添加标签到home-bar
    addPath: (state, obj) => {
      if (state.pathArr.length > 0) {
        for (let i = 0; i < state.pathArr.length; i++) {
          if (state.pathArr[i].name.indexOf(obj.n2) > -1) {
            state.pathArr[i].path = obj.n1;
            state.homebarThisIndex = i;
            return;
          }
        };
          state.pathArr.push({
            path: obj.n1,
            name: obj.n2
          });
          state.homebarOneTime = true;
      }
      for (let i = 0; i < state.pathArr.length; i++) {
        if (state.pathArr[i].name.indexOf(obj.n2) > -1) {
          state.homebarThisIndex = i;
        }
      }

    },
    //删除home-bar
    deleteThisHomebar: (state, index) => {
      state.pathArr.splice(index, 1);
    }
  }
})